import request from '@/utils/request'
import axios from 'axios'
//呼叫质量分析

export function hasAllByCallReport(params) {
  return request({
    url: '/TBaseTask/hasAllByCallReport',
    method: 'get',
    params
  })
}

export function exportExcel(url, options = {}) {

  return new Promise((resolve, reject) => {
    console.log(`${url} 请求数据，参数=>`, JSON.stringify(options))
    axios.defaults.headers['content-type'] = 'application/json;charset=UTF-8'
    axios({
      method: 'get',
      url: url, // 请求地址
      data: options, // 参数
      responseType: 'blob' // 表明返回服务器返回的数据类型
    }).then(
      response => {
        resolve(response.data)
        let blob = new Blob([response.data], {
          type: 'application/vnd.ms-excel'
        })
        const contentDisposition = response.headers['content-disposition'];

        // 进一步处理contentDisposition
        console.log(contentDisposition);
        const fruits = contentDisposition.split(";"); // 使用逗号作为分隔符
        const str = fruits[1].split("=")
        console.log(str);  
        console.log(decodeURIComponent(str[1]))
        let fileName = decodeURIComponent(str[1]).substring(7)
        if (window.navigator.msSaveOrOpenBlob) {
          // console.log(2)
          navigator.msSaveBlob(blob, fileName)
        } else {
          // console.log(3)
          var link = document.createElement('a')
          link.href = window.URL.createObjectURL(blob)
          link.download = fileName
          link.click()
          //释放内存
          window.URL.revokeObjectURL(link.href)
        }
      },
      err => {
        reject(err)
      }
    )
  })
  return request({
    url: '/Excel/exportExcel',
    method: 'get',
    params
  })

}

export function qualityAnalysisOfPatientTransportation(params) {
  return request({
    url: '/TBaseTask/qualityAnalysisOfPatientTransportation',
    method: 'get',
    params
  })
}
